﻿using System;
using System.Diagnostics;
using Rhizome.QuickStart.Elevator.Contract;

namespace Rhizome.QuickStart.Elevator.Model
{
	public class ElevatorModel : ModelBase, IElevator
	{
		private bool _downChecked;
		private bool _isOpen;
		private double _position;
		private int _timeOut;
		private bool _upChecked;

		private int _workTime;
		public Shaft Shaft { get; set; }

		#region IElevator Members

		public int WorkTime
		{
			[DebuggerStepThrough]
			get { return _workTime; }
			set
			{
				if (_workTime == value) return;
				_workTime = value;
				InvokePropertyChanged("WorkTime");
			}
		}

		public double Position
		{
			[DebuggerStepThrough]
			get { return _position; }
			set
			{
				if (_position == value) return;
				_position = value;
				InvokePropertyChanged("Position");
			}
		}

		public int TimeOut
		{
			[DebuggerStepThrough]
			get { return _timeOut; }
			set
			{
				if (value == _timeOut) return;
				_timeOut = value;
				InvokePropertyChanged("TimeOut");
			}
		}

		public bool IsOpen
		{
			[DebuggerStepThrough]
			get { return _isOpen; }
			set
			{
				if (_isOpen == value) return;
				_isOpen = value;
				InvokePropertyChanged("IsOpen");
			}
		}

		public void InvokeUpClick()
		{
			var handler = UpClick;
			if (handler != null) handler(this, EventArgs.Empty);
		}

		public void InvokeDownClick()
		{
			var handler = DownClick;
			if (handler != null) handler(this, EventArgs.Empty);
		}

		public void InvokeStopClick()
		{
			var handler = StopClick;
			if (handler != null) handler(this, EventArgs.Empty);
		}

		public bool UpChecked
		{
			[DebuggerStepThrough]
			get { return _upChecked; }
			set
			{
				if (_upChecked == value) return;
				_upChecked = value;
				InvokePropertyChanged("UpChecked");
			}
		}

		public bool DownChecked
		{
			[DebuggerStepThrough]
			get { return _downChecked; }
			set
			{
				if (_downChecked == value) return;
				_downChecked = value;
				InvokePropertyChanged("DownChecked");
			}
		}

		#endregion

		public event EventHandler UpClick;
		public event EventHandler DownClick;
		public event EventHandler StopClick;
	}
}